package com.jsh.erp.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 */
public class ObjectMapperUtils {

    private static Logger logger = LoggerFactory.getLogger(ObjectMapperUtils.class);

    static ObjectMapper objectMapper = new ObjectMapper();

    public static  <T> String writeToJsonString(T obj){
        try{
            return objectMapper.writeValueAsString(obj);
        }catch (Exception e){
            logger.error("对象转换字符串失败",e);
        }
        return null;
    }


    public static <T> T readFromJsonString(String jsonStr,Class<T> var2){

        try{
            return  objectMapper.readValue(jsonStr,var2);
        }catch (Exception e){
            logger.error("字符串转换对象失败",e);
        }
        return null;



    }

}
